import 'package:flutter/material.dart';
import "./res/listData.dart";

void main() {
  runApp(
    MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('你好flutter1')),
        body: const MyApp(),
      ),
    ),
  );
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  List<Widget> _initCardData() {
    var tempList = listData.map((item) {
      return Card(
        margin: const EdgeInsets.all(10),
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(20),
        ),
        elevation: 10,
        child: Column(
          children: [
            AspectRatio(
              aspectRatio: 16 / 9,
              child: Image.network(
                item['imageUrl'],
                fit: BoxFit.cover,
              ),
            ),
            ListTile(
              title: Text(item['title']),
              subtitle: Text(item['author']),
              leading: CircleAvatar(
                backgroundImage: NetworkImage(item['imageUrl']),
              ),
            )
          ],
        ),
      );
    });

    return tempList.toList();
  }

  @override
  Widget build(BuildContext context) {
    return ListView(
      children: [
        Card(
          // 阴影
          elevation: 20,
          // 背景
          color: Colors.amber,
          // 圆角
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(30),
          ),
          child: const Column(
            children: [
              ListTile(
                title: Text(
                  'title',
                  style: TextStyle(fontSize: 28),
                ),
                subtitle: Text('subtitle'),
              ),
              Divider(),
              ListTile(
                title: Text('电话:182****9004'),
              ),
              ListTile(
                title: Text('地址:四川成都。。。。。 '),
              ),
            ],
          ),
        ),
        const SizedBox(height: 20),
        Column(
          children: _initCardData(),
        )
      ],
    );
  }
}
